package com.lzh.chatnote.user.dao;

import com.lzh.chatnote.common.antation.RedisLock;
import com.lzh.chatnote.common.mqConsumer.IdempotentEnum;
import com.lzh.chatnote.common.service.RedisService;
import com.lzh.chatnote.user.domain.entity.ItemConfig;
import com.lzh.chatnote.user.domain.entity.UserBackpack;
import com.lzh.chatnote.user.domain.enums.ItemTypeEnum;
import com.lzh.chatnote.user.domain.enums.YesOrNoEnum;
import com.lzh.chatnote.user.mapper.UserBackpackMapper;
import com.lzh.chatnote.user.service.UserBackpackService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lzh.chatnote.user.service.cache.ItemCache;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
 * <p>
 * 用户背包表 服务实现类
 * </p>
 *
 * @author lzh
 * @since 2025-09-25
 */
@Service
public class UserBackpackDao extends ServiceImpl<UserBackpackMapper, UserBackpack>  {

    public List<UserBackpack> containBadge(Long uuid, Integer type, Set<Long> allBadgeIds) {
        return lambdaQuery().eq(UserBackpack::getUid, uuid)
                .eq(UserBackpack::getItemType, type)
                .in(UserBackpack::getItemId, allBadgeIds)
                .select(UserBackpack::getItemId)
                .eq(UserBackpack::getStatus, YesOrNoEnum.NO.getType())
                .list()
                ;
    }

    public UserBackpack existAcquireItem(Long uuid, Long itemId) {
        return lambdaQuery()
                .eq(UserBackpack::getUid, uuid)
                .eq(UserBackpack::getItemId, itemId)
                .eq(UserBackpack::getStatus, YesOrNoEnum.NO.getType())
                .one();
    }

    public List<UserBackpack> batchAcquireItems(List<Long> uids, List<Long> itemIds) {
        return lambdaQuery()
                .in(UserBackpack::getUid, uids)
                .in(UserBackpack::getItemId, itemIds)
                //未使用的
                .eq(UserBackpack::getStatus, YesOrNoEnum.NO.getType())
                .list();
    }
}
